<template>
	<a-modal :confirm-loading="handing" :width="800" v-model:open="open" @ok="submit">
		<a-form ref="form" :model="formData" :rules="rules" :labelCol="{ span: 5 }" :wrapper-col="{ span: 16, offset: 1 }">
			<a-form-item name="title" label="活动标题">
				<a-input v-model:value="formData.title" placeholder="活动标题" />
			</a-form-item>
			<a-form-item name="duration" label="时长(元)">
				<a-input-number v-model:value="formData.duration" placeholder="展示给用户的时长" :min="1" step="10" addon-after="元" />
			</a-form-item>
			<a-form-item name="fee" label="人均(元)">
				<a-input-number v-model:value="formData.fee" placeholder="实际结算价格" :min="1" step="10" addon-after="元" />
			</a-form-item>
			<a-form-item name="cover" label="封面图">
        <avatar-uploader v-model:value="formData.cover" placeholder="封面图" />
			</a-form-item>
			<a-form-item name="dist_id" label="地区">
				<a-textarea v-model:value="formData.dist_id" placeholder="地区" />
			</a-form-item>
			<a-form-item name="mobile" label="联系方式">
				<editor v-model:value="formData.mobile" placeholder="联系方式" />
			</a-form-item>
		</a-form>
	</a-modal>
</template>
<script lang="ts">
import {page, form} from "@/mixins"

export default {
	mixins: [page, form],
	data() {
		return {
			open: false as boolean,
			formPath: 'activity',
			formData: {
				id: undefined,
				title: '',
				duration: '',
				fee: '',
				cover: '',
				dist_id: '',
        mobile: ''
			},
			rules: {
			  title: [{ required: true, trigger: 'change', message: '活动标题不能为空' }],
			  duration: [{ required: true, trigger: 'change', message: '请选择时长' }],
			  fee: [{ required: true, trigger: 'change', message: '请填写人均' }],
			  cover: [{ required: true, trigger: 'change', message: '请上传封面图片' }],
				dist_id: [{ required: true, trigger: 'change', message: '地区不能为空' }],
				mobile: [{ required: true, trigger: 'change', message: '联系方式不能为空' }]
			}
		}
	},
	methods: {
		add() {
			Object.assign(this.formData, {
				id: undefined,
				title: '',
        duration: 4,
				fee: 0,
				cover: '',
				dist_id: 0,
				mobile: ''
			})
			this.open = true;
		},
		edit(record: object) {
			Object.assign(this.formData, record);
			this.open = true
		},
		afterSubmit(data: object){
			this.$emit('change', data);
			this.open = false
		}
	}
}
</script>